<?php
/**
 * Created by PhpStorm.
 * User: liang
 * Email:1050187159@qq.com
 * Date: 2018/8/18
 * Time: 16:42
 */
namespace Admin\Controller;

class SetController extends BaseController
{
    public function index()
    {
        if (!IS_POST) {
            $sets =file_get_contents(APP_PATH.'set-basic.json');
            $sets = json_decode($sets,true);
            $this->assign(array(
                'sets' => $sets
            ));
            $this->display('Set/index');
            exit;
        }

        $website = I('post.website');
        $address = I('post.address');
        $seat_machine = I('post.seat_machine');
        if (empty($website)) {
            $this->ajaxReturn('网站备案号必填');
        }
        if (empty($address)) {
            $this->ajaxReturn('公司地址必填');
        }
        if (empty($seat_machine)) {
            $this->ajaxReturn('财富热线电话必填');
        }
        $array = array(
            'website'  => $website,
            'address'  => $address,
            'seat_machine' => $seat_machine
        );
        $result = file_put_contents(APP_PATH.'set-basic.json',json_encode($array));
        if ($result) {
            $this->ajaxReturn('true');
        } else {
            $this->ajaxReturn('设置失败,请稍后重试');
        }
    }


    public function contact()
    {
        if (!IS_POST) {
            $content = file_get_contents(APP_PATH.'contact.json');
            $this->assign(array(
                'content' => htmlspecialchars_decode(json_decode($content))
            ));
            $this->display('Set/add');
            exit;
        }
        $content = I('post.content');
        file_put_contents(APP_PATH.'contact.json', json_encode($content));
        $this->ajaxReturn('true');
    }
}
